﻿using System;
using COUP.Core.Enums;

namespace COUP.Core.Networking
{
    public unsafe class GeneralDataPacket : Packet
    {
        public GeneralDataPacket(int Ident, int ValueA, int ValueB, int ValueC,
            int ValueD, GeneralDataType pSubType)
        {
            Length = 28;
            Type = 1010;
            Int(Environment.TickCount);
            Identifier = Ident;
            Short(ValueA);
            Short(ValueB);
            Short(ValueC);
            Int(ValueD, 20);
            SubType = pSubType;
        }

        public GeneralDataPacket(Packet Data)
        {
            buffer = Data.Buffer;
        }

        public int Identifier
        {
            get
            {
                fixed (byte* ptr = buffer)
                    return (int)(*(int*)(ptr + 8));
            }

            set
            {
                Int(value, 8);
            }
        }

        public int UniqueID
        {
            get
            {
                fixed (byte* ptr = buffer)
                    return (int)(*(int*)(ptr + 20));
            }
        }

        public int X
        {
            get
            {
                fixed (byte* ptr = buffer)
                    return (int)(*(ushort*)(ptr + 20));
            }
        }

        public int Y
        {
            get
            {
                fixed (byte* ptr = buffer)
                    return (int)(*(ushort*)(ptr + 22));
            }
        }

        public byte Action
        {
            get
            {
                fixed (byte* ptr = buffer)
                    return (byte)*(ptr + 12);
            }
        }

        public Direction Angle
        {
            get
            {
                fixed (byte* ptr = buffer)
                    return (Direction)(*(ptr + 16));
            }
        }

        public PlayerKillMode PkMode
        {
            get
            {
                fixed (byte* ptr = buffer)
                    return (PlayerKillMode)(*(ptr + 20));
            }
        }

        public GeneralDataType SubType
        {
            get
            {
                fixed (byte* ptr = buffer)
                    return (GeneralDataType)(*(ptr + 24));
            }

            set
            {
                Byte((byte)value, 24);
            }
        }
    }
}
